package com.example.baidumapsum;



import com.example.location.BaiduLocation;
import com.example.location.DragShowLocation;
import com.example.location.GetLatlonBounsActivity;
import com.example.location.MultiLocationActivity;
import com.example.location.SelectMylocationActivity;
import com.example.location.ShowLatlonActivity;
import com.example.location.ShowMylocationActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends FragmentActivity {

	private TextView address;
	private BaiduLocation baiduLoc;
	private Context context;
	private View myLacation;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		context=this;
		innitUi();
		initListener();
		startLocation();
	}
    /**
     * 监听设置
     */
    private void initListener() {
    	//显示我的位置
    	myLacation.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				startClass(ShowMylocationActivity.class);
			}
		});
    	//点击改变位置
    	findViewById(R.id.select_mylocation).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				startClass(SelectMylocationActivity.class);
			}
		} );
    	//显示经纬度坐标的位置
    	findViewById(R.id.showlatlon_location).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				startClass(ShowLatlonActivity.class);
			}
		});
    	//显示多个位置
    	findViewById(R.id.multilalon_location).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				startClass(MultiLocationActivity.class);
			}
		});
    	//获取当前屏幕的经纬度范围
    	findViewById(R.id.screet_latlonbounds).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				//do something
				startClass(GetLatlonBounsActivity.class);
			}
		});
    	//拖动显示我的位置
    	findViewById(R.id.drag_showlocation).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				startClass(DragShowLocation.class);
			}
		});
		
	}
	/**
	 * @param cls 
	 * 
	 */
	private void startClass(Class<?> cls) {
		startActivity(new Intent(context, cls));
	}
	/**
     * 开始定位
     */
	private void startLocation() {
		baiduLoc=new BaiduLocation(address);
		baiduLoc.initLocation(context);
		
	}

	private void innitUi() {
		address=(TextView)findViewById(R.id.address_text);
		myLacation=findViewById(R.id.show_mylocation);
		
	}
	@Override
	public void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		baiduLoc.stopLocation();
	}
}
